using Autofac;
using Hr.BLL;
using Hr.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hr.BLLContainer
{
    public class Container
    {
        /// <summary>
        /// IOC 容器
        /// </summary>
        public static IContainer container = null;

        /// <summary>
        /// 获取 IDal 的实例化对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Resolve<T>()
        {
            try
            {
                if (container == null)
                {
                    Initialise();
                }
            }
            catch (Exception ex)
            {

                throw new Exception("IOC实例化出错！" + ex.Message);
            }
            return container.Resolve<T>();
        }

        public static void Initialise()
        {
            var builder = new ContainerBuilder();
            //格式：builder.RegisterType<xxxx>().As<Ixxxx>().InstancePerLifetimeScope();
            //任务管理业务层注入
            builder.RegisterType<TaskService>().As<ITask_ListService>().InstancePerLifetimeScope();
            //流程管理业务层注入
            builder.RegisterType<ProcessService>().As<IProcess_ListService>().InstancePerLifetimeScope();
            // 角色业务层注入
            builder.RegisterType<RoleService>().As<IRole_NameService>().InstancePerLifetimeScope();
            // 登录业务层注入
            builder.RegisterType<LoginService>().As<IUser_ListService>().InstancePerLifetimeScope();
            // 用户管理注入
            builder.RegisterType<UserService>().As<IUser_ListService>().AsImplementedInterfaces();
            // 简历业务层注入
            //builder.RegisterType<ResumeListService>().As<IResume_ListService>().InstancePerLifetimeScope();
            //车辆管理注入
            builder.RegisterType<CarService>().As<ICar_ListService>().InstancePerLifetimeScope();
            //公告信息注入
            builder.RegisterType<NoticeService>().As<INoticeService>().InstancePerLifetimeScope();
            //菜单层注入
            builder.RegisterType<MenuService>().As<ISys_MenuService>().InstancePerLifetimeScope();
            container = builder.Build();
        }

    }
}
